package net.y2t72.microblog.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;

import net.y2t72.microblog.biz.DistrictBiz;
import net.y2t72.microblog.biz.impl.DistrictBizImpl;
import net.y2t72.microblog.util.StringUtil;

public class FindCityNextServlet extends HttpServlet {

	/**
	 *  版本号
	 */
	private static final long serialVersionUID = -5768896997807382934L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		// 编码字符 
		response.setContentType("text/html;charset=utf-8");
		
		// 想控制台输出用户想要得到的信息
		PrintWriter out = response.getWriter();
		
		String provinceId = request.getParameter("provinceId");
		int upid = 0;
		if(provinceId != null){
			upid = StringUtil.parseInt(provinceId);
		}
		
		// 创建城市业务对象
		DistrictBiz districtBiz = new DistrictBizImpl();
		
		// 根据省市upid查询二级城市的名称
		List<String> list = districtBiz.getList(upid);
		
		if(list!= null && list.size()>0){
			//创建绑定对象
			ObjectMapper mapper = new ObjectMapper();
			mapper.writeValue(out, list);
		}
		out.flush();
		out.close();
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		this.doGet(request, response);
	}
}
